/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Dao;

import Interface.InterfaceAddress;
import Pojo.Address;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author olegk
 */
public class DaoAddress implements InterfaceAddress{
    
    @Override
    public boolean register(Session session, Address address) throws Exception {
        session.save(address);        
        return true;
    }
    
    @Override
    public boolean update(Session session, Address address) throws Exception {
        session.update(address);
        return true;
    }
    
    @Override
    public boolean delete(Session session, Address address) throws Exception {
        session.delete(address);
        return true;
    }

    @Override
    public List<Address> getAll(Session session) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public Address selectAddress(Session session, String hql, List<Object> param) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public List<Address> selectListAddress(Session session, String hql, List<Object> param) throws Exception {
        Query query=session.createQuery(hql);
        for(Object inParam:param){
            query.setParameter(param.indexOf(inParam), inParam);
        }       
        List<Address> listOrganization =(List<Address>) query.list();        
        return listOrganization;
    }
    
}
